package com.sample.action;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.sample.action.form.TeacherForm;
import com.sample.javabean.Teacher;
import com.sample.util.Pager;

     /**
     * @author梁桂花
     *
     * 2018-6-20
     */
           public class TeacherAction extends BaseAction {
    	 
      
    	   private final static Log log=LogFactory.getLog(TeacherAction.class);
    	 	private Pager<Teacher> pageList;
    	 	private String cardno;
    	 	private Teacher teacher=new Teacher();
    	 	private TeacherForm teacherForm=new TeacherForm();
    	 	
    	 	
    	 	/**
    	 	 * 教师信息录入界面
    	 	 * @return
    	 	 * @throws Exception
    	 	 */
    	 	public String inputTeacher()throws Exception{
    	 		
    	 		return "inputTeacher";
    	 	}
    	 	/**
    	 	 * 
    	 	 * @return
    	 	 * @throws Exception
    	 	 */
    	 	public String save()throws Exception{
    	 		try{
    	 			log.info("添加教师信息");
    	 			if(teacherForm!=null){
    	 				Teacher teacher =new Teacher();
    	 				
    	 				teacher.setName(teacherForm.getName());
    	 				teacher.setSex(teacherForm.getSex());
    	 				teacher.setCardno(teacherForm.getCardno());
    	 				teacher.setAddress(teacherForm.getAddress());
    	 				teacher.setClassName(teacherForm.getClassName());
    	 				teacher.setTel(teacherForm.getTel());
    	 				
    	 				
    	 			   //调用方法
    	 				teacher.add();
    	 			}
    	 			return SUCCESS;
    	 		}catch (Exception e) {
    	 			e.printStackTrace();
    	 			
    	 		}
    	 		return "inputTeacher";
    	 	}
    	 	
    	 	public String list()throws Exception{
    	 		Teacher teacherModel =new Teacher();
    	 		pageList =teacherModel.list(page,size,teacherForm);
    	 		return "listTeacher";
    	 	}
    	 	public String del()throws Exception{
    	 		try{
    	 			if(teacherForm!=null){
    	 				teacher.setCardno(cardno);
    	 				teacher.delTeacher();	
    	 			}
    	 			return SUCCESS;
    	 		}catch (Exception e) {
    	 			e.printStackTrace();
    	 			throw e;
    	 		}	
    	 	}
    	 	public String editTeacher()throws Exception{
    	 		try{
    	 			teacher.setCardno(cardno);
    	 			teacher.load();
    	 			return "editTeacher";
    	 		}catch (Exception e) {
    	 			e.printStackTrace();
    	 			throw e;
    	 		}	
    	 	}
    	 	/**
    	 	 * 
    	 	 * @return
    	 	 * @throws Exception
    	 	 */
    	 	public String edit()throws Exception{
    	 		try{
    	 			
    	 			if(teacherForm!=null){
    	 				teacher.setName(teacherForm.getName());
    	 				teacher.setSex(teacherForm.getSex());
    	 				teacher.setCardno(teacherForm.getCardno());
    	 				teacher.setAddress(teacherForm.getAddress());
    	 				teacher.setClassName(teacherForm.getClassName());
    	 				teacher.setTel(teacherForm.getTel());
    	 				teacher.editTeacher();	
    	 			}
    	 			return SUCCESS;
    	 		}catch (Exception e) {
    	 			e.printStackTrace();
    	 			throw e;
    	 		}	
    	 	}
			public Pager<Teacher> getPageList() {
				return pageList;
			}
			public void setPageList(Pager<Teacher> pageList) {
				this.pageList = pageList;
			}
			public String getCardno() {
				return cardno;
			}
			public void setCardno(String cardno) {
				this.cardno = cardno;
			}
			public Teacher getTeacher() {
				return teacher;
			}
			public void setTeacher(Teacher teacher) {
				this.teacher = teacher;
			}
			public TeacherForm getTeacherForm() {
				return teacherForm;
			}
			public void setTeacherForm(TeacherForm teacherForm) {
				this.teacherForm = teacherForm;
			}
			public static Log getLog() {
				return log;
			}
		

    	
}
